package org.example.serv;

import org.example.dao.UserMapper;
import org.example.dto.User;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author author
 * @since 2024-11-08
 */
@Component
public class UserServ {
    @Resource
    UserMapper userMapper;
    @Resource
    @Lazy
    UserServ userServ;

    @Transactional
    public void test() {
        userMapper.insert(new User("tom", 23));
//        userServ.test2();
        test2();
//        throw new RuntimeException("123");

    }

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public void test2() {
        userMapper.insert(new User("bob", 15));
        throw new RuntimeException("123");
    }
}
